﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace LinearAlgebra
{
    public partial class InverseExplain2DDialog : Form
    {
        float[,] matrix = new float[2, 2];
        float determinate;
        // This list is assumed to be row major
        public InverseExplain2DDialog(float x, float z, float y, float w)
        {            
            InitializeComponent();

            matrix[0, 0] = x;
            matrix[0, 1] = y;
            matrix[1, 0] = z;
            matrix[1, 1] = w;

            determinate = matrix[0, 0] * matrix[1, 1] - matrix[0, 1] * matrix[1, 0];

            Determinant_1.Text = determinate.ToString("0.00", CultureInfo.InvariantCulture);
            Determinant_2.Text = determinate.ToString("0.00", CultureInfo.InvariantCulture);

            A11_S.Text = matrix[0,0].ToString("0.00", CultureInfo.InvariantCulture);
            A12_S.Text = matrix[0,1].ToString("0.00", CultureInfo.InvariantCulture);
            A21_S.Text = matrix[1,0].ToString("0.00", CultureInfo.InvariantCulture);
            A22_S.Text = matrix[1,1].ToString("0.00", CultureInfo.InvariantCulture);

            A11_1.Text = matrix[0,0].ToString("0.00", CultureInfo.InvariantCulture);
            A12_1.Text = matrix[0,1].ToString("0.00", CultureInfo.InvariantCulture);
            A21_1.Text = matrix[1,0].ToString("0.00", CultureInfo.InvariantCulture);
            A22_1.Text = matrix[1,1].ToString("0.00", CultureInfo.InvariantCulture);

            A11_2.Text = matrix[0,0].ToString("0.00", CultureInfo.InvariantCulture);
            A12_2.Text = matrix[0,1].ToString("0.00", CultureInfo.InvariantCulture);
            A21_2.Text = matrix[1,0].ToString("0.00", CultureInfo.InvariantCulture);
            A22_2.Text = matrix[1,1].ToString("0.00", CultureInfo.InvariantCulture);

            A11_3.Text = matrix[0,0].ToString("0.00", CultureInfo.InvariantCulture);            
            A22_3.Text = matrix[1,1].ToString("0.00", CultureInfo.InvariantCulture);

            A11_4.Text = matrix[0,0].ToString("0.00", CultureInfo.InvariantCulture);
            A22_4.Text = matrix[1,1].ToString("0.00", CultureInfo.InvariantCulture);

            A12_neg_1.Text = (-matrix[0,1]).ToString("0.00", CultureInfo.InvariantCulture);
            A21_neg_1.Text = (-matrix[1,0]).ToString("0.00", CultureInfo.InvariantCulture);

            A12_neg_2.Text = (-matrix[0,1]).ToString("0.00", CultureInfo.InvariantCulture);
            A21_neg_2.Text = (-matrix[1,0]).ToString("0.00", CultureInfo.InvariantCulture);            

            Result11.Text = (matrix[1,1]/determinate).ToString("0.00", CultureInfo.InvariantCulture);
            Result12.Text = (-matrix[0,1]/determinate).ToString("0.00", CultureInfo.InvariantCulture);
            Result21.Text = (-matrix[1,0]/determinate).ToString("0.00", CultureInfo.InvariantCulture);
            Result22.Text = (matrix[0,0]/determinate).ToString("0.00", CultureInfo.InvariantCulture);
        }
    }
}
